package na.edu.polytechnic;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class TipCalculator extends Activity implements View.OnClickListener{
   private Button btn;
   private EditText et;
   private TextView tv;
   double value;
   String result;
   @Override
   public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.tipcalc);
      btn=(Button)findViewById(R.id.btn_calc);
      btn.setOnClickListener(this);
   }

   public void onClick(final View view) {
      et= (EditText)findViewById(R.id.value_calc);
      value = Double.parseDouble(et.getText().toString());
      result="\n\n The Tip is : "+(value*0.15);
      tv = (TextView)findViewById(R.id.result_calc);
      tv.setText(result);
      et.setText("");
      Toast.makeText(TipCalculator.this, "Tip Calculated", Toast.LENGTH_SHORT).show();
   }

   @Override
   public boolean onKeyDown(final int keyCode, final KeyEvent msg) {
      if(keyCode == KeyEvent.KEYCODE_BACK) {
         finish();
      }
      return true;
   }
}